"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createView = void 0;
const koa_router_1 = __importDefault(require("koa-router"));
const controller_1 = require("../controller");
const dayjs_1 = __importDefault(require("dayjs"));
function createView(config) {
    return __awaiter(this, void 0, void 0, function* () {
        const router = new koa_router_1.default();
        const { host } = config;
        const mark = new controller_1.MarkApi(host, '/api/v3');
        router.get('/', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
            const data = [];
            const priceData = yield mark.price();
            for (const item of priceData) {
                data.push(item.symbol);
            }
            ctx.set('Content-Type', 'application/json');
            yield ctx.render('index', { pair: data });
        }));
        router.get('/index2', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
            const data = [];
            const priceData = yield mark.price();
            for (const item of priceData) {
                data.push(item.symbol);
            }
            dayjs_1.default().format("YYYY-MM-DD");
            ctx.set('Content-Type', 'application/json');
            yield ctx.render('index2', { pair: data });
        }));
        router.get('/getAllCoin', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
            const coins = [];
            const priceData = yield mark.price();
            for (const item of priceData) {
                coins.push(item.symbol);
            }
            ctx.set('Content-Type', 'application/json');
            ctx.body = coins;
        }));
        router.get('/getKlinesTime', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
            const arr = [];
            const query = ctx.query;
            const times = yield mark.kinesTime(query);
            ctx.set('Content-type', 'application/json');
            ctx.body = times;
        }));
        router.get('/klines', (ctx, next) => __awaiter(this, void 0, void 0, function* () {
            const query = ctx.query;
            let klines = yield mark.klinesByTime(query);
            ctx.set('Content-Type', 'application/json');
            ctx.body = klines;
        }));
        const ret = router.routes();
        return ret;
    });
}
exports.createView = createView;
